package BehaviorModel.strategyModel.discountCalculation;


// 上下文对象,集成策略接口,各种行为策略的调用者
public class ShoppingCart {

    private DiscountStrategy discountStrategy;


    public void setDiscountStrategy(DiscountStrategy discountStrategy) {
        this.discountStrategy = discountStrategy;
    }

    /**
     * 功能描述: 折扣计算
     *
     * @param price
     * @return double
     */
    public double calculateDiscount(double price) {
        if (discountStrategy == null){
            throw new RuntimeException("discountStrategy is null");
        }
        return discountStrategy.calculateDiscount(price);
    }
}
